<?php

use yii\widgets\LinkPager;
use yii\helpers\Html;
use yii\helpers\Url;

?>
<div style="height:5px"></div>

<form class="form-inline"> 
    <div class="form-group"> 
        <label>姓名:</label>
        <input type="text" class="form-control border-input" name="realname" value="<?= $realname?>">
    </div> 
    <div class="form-group">
        <label>联系方式:</label>
        <input type="text" class="form-control border-input" name="tel" value="<?=$tel ?>">
    </div>   
   
    <button type="submit" class="btn btn-info" style="margin-top: 6px" >搜 索</button>
</form>

    <table id="dnd-example" cellspacing="0" class="table table-striped table-hover">
        <thead>
            <tr>
                <th style="width:80px;">ID</th>
                <th>姓名</th>
                <th>性别</th>
                <th>联系方式</th>
                <th>地址</th>
                <th align="center">操作</th>
            </tr>
        </thead>

        <tbody>

            <?php
            $users=$dataProvider->getModels();  

            foreach($users as $user)
            {
            ?>
            <tr id="user_<?=$user->id;?>">
                <td><?= $user->id;?></td>
                <td><?= $user->realname;?></td>
                <td><?= $user->gender;?></td>
                <td><?= $user->tel;?></td>
                <td><?=$user->info?></td>
                <td>
                    <a href="<?php echo  Url::toRoute(['user/view', 'id' => $user->id]);?>">
                        <button type="button" class="btn btn-info">查看</button>
                    </a>
                    <a href="<?php echo  Url::toRoute(['user/update', 'id' => $user->id]);?>">
                        <button type="button" class="btn btn-success">编辑</button>
                    </a>
                    <a onclick="del(<?=$user->id?>)">
                        <button type="button" class="btn btn-danger">删除</button>
                    </a>
                </td>
            </tr>
                    
            <?php }?>
        </tbody>
        </table> 

<?php 
$pages=$dataProvider->getPagination();
echo LinkPager::widget([
    'pagination' => $pages,
    ]);

?>

<?php $this->beginBlock('opt') ?>

//    删除角色
function del(id)
{
    layer.confirm(
    '确定删除该党员？',
    {icon: 5, title:'删除'},
    function(index){
        $.get("<?=Url::toRoute(['user/delete'])?>", {id:id},
        function(data){
            if(data.status == -1){
                $("#user_"+id).hide();
            }
        layer.msg(data.msg);
    });
    layer.close(index);
    });
}
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['opt'], \yii\web\View::POS_END);?>